package com.ymatou.iapi.livemanage.testcase;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.livemanage.service.GetActivityInfoCall;
import com.ymatou.iapi.livemanage.service.ListHistoryMarketsCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.LiveCallService;
import com.ymttest.utils.EnvSetup;

public class Ts_ListHistoryMarkets {
	private static String sellerId = EnvSetup.getData("productsellerid");
	private static String sellerName = EnvSetup.getData("productsellername");
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("直播Admin-选择已有扫货地");
	}

	@Before
	public void caseUp() {
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(new ListHistoryMarketsCall().getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	
	
	 @Test
	 @Category(P1.class)
	 @TestCase
	public void Tc_ListHistoryMarkets_001() {
		 Logger.start(true,"直播Admin-选择已有扫货地");
		 try{
			//1.创建将要开始的直播
			 JSONObject createLiveReq = LiveCallService.createLiveNotInEffect(sellerName,Integer.parseInt(sellerId));
			int liveId = createLiveReq.getJSONObject("Data").getInt("ActivityId");
				
			//2. 查询直播获取country id
			
			GetActivityInfoCall getActivityInfoCall = new GetActivityInfoCall();
			getActivityInfoCall.setData(liveId, Integer.parseInt(sellerId));
			getActivityInfoCall.callService();
			JSONObject activityInfoBean = new JSONObject(getActivityInfoCall.getReturnData());
			
			int countryId = activityInfoBean.getJSONObject("Data").getInt("CountryId");
			
			//3 选择扫货地
			ListHistoryMarketsCall listHistoryMarketsCall = new ListHistoryMarketsCall();
			listHistoryMarketsCall.setData("CountryId="+countryId+"&SellerId="+Integer.parseInt(sellerId));
			listHistoryMarketsCall.callService();
			JSONObject listHistoryMarketsBean = new JSONObject(listHistoryMarketsCall.getReturnData());
			 
			//check
			Logger.verifyEquals(200,listHistoryMarketsBean.getInt("Code"), "响应报文-返回码");
			Logger.verifyEquals(true, listHistoryMarketsBean.getJSONObject("Data").getJSONArray("UserMarketList").length()>0, "响应报文-UserMarketList");
			
			
			
			
			 
		 }catch (Exception e){
			 Logger.fail(e);
		 }
		 
	 }
}
